home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_10
/
1010014b
< prev
next >
Wrap
Text File
|
1992-08-11
|
452b
|
21 lines
Listing 3 -- the file memmove.c
/* memmove function */
#include <string.h>
void *(memmove)(void *s1, const void *s2, size_t n)
{ /* copy char s2[n] to s1[n] safely */
char *sc1 = (char *)s1;
const char *sc2 = (const char *)s2;
if (sc2 < sc1 && sc1 < sc2 + n)
for (sc1 += n, sc2 += n; 0 < n; --n)
*--sc1 = *--sc2; /*copy backwards */
else
for (; 0 < n; --n)
*sc1++ = *sc2++; /* copy forwards */
return (s1);
}